const formidable = require('formidable');
const {Article} = require('../../model/article');
const path = require('path');
module.exports = async (req, res)=>{
    const form = new formidable.IncomingForm();
    form.uploadDir = path.join(__dirname,'../','../','public','uploads');
    form.keepExtensions = true;
    form.parse(req,async (err, fields,files)=>{
        //err存储错误信息，fields存储普通参数，files存储上传的文件
         await Article.create({
            title: fields.title,
             author: fields.author,
             publishDate: fields.publishDate,
             cover: files.cover.path.split('public')[1],
             content:fields.content
        });
         res.redirect('/admin/article');
        // res.send(files.cover.path.split('public')[1]);
    })
};
